#!/bin/sh
#作用： 检查软件符合优选要求
#
scanningPath="/usr1/jenkins/EulerOS/$GERRIT_PROJECT"
added_key="[dgggit09-rd.huawei.com]:29418,[10.1.21.40]:29418 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAxhN+TnUC8a91hpMJmuYMOl+X7S2XlyGhhIQEBvZTcjqF/FXN2u9Jn4SkeXsAi6J+P1q3nFKbgqQKpug2f41Q6xufXn4wsnACcjVAzVmSSe+qvMUh84oiI7j7c7MZ9iQhxgMzrJIMoP20wsVjEyQtT2jlrxb8+h6dzq+sk2HhX4wA+rsIOFrSQvKdIjrphCoVJ+vadX+dtk5BD+Etdu22XlPl3AfZONpssPmEc/hM96u44NtHE+BujDhBhXYW8VKYKW1ZiQ0x/27YR2jss572jlEegOCMq/GmoiRwWM7Y7ZBZ8rrEg85lpjIDKCfh8r1Hiz6wrrWfQGdSHukUEL2aqQ=="

added_key_id_rsa="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDU/h5m79Voc4Kzyf9bNardbQYuSicnOc4ERv5tAtZOgAZwV9s4M4J7++ZxugFPUcbJs9nIHwlhBNVSxWcgnp7DlfEzysuv72dIwrEobdEUiIpKv9GuHNWvJRM0ltRVIlO1P4iUAwqPXaCCMOEARKL3qVNVmuZM1UcgGOLBxq2V/mqJdf8S1vYTu7lOxwhSHSJLxzhaYNViOKiPrjMaVRkieOLLLiqjZE4pgXgM3bl+2huR9Gamo2ZWTCLJ2Y+Ueek4tfHMvzTurXFYEVCjBJfd6YpJ55wh6HqiXsd5biyM2bNECGSDnRGk52qLh43RR+BLxB1soCpoULP/T52G6QSX eulerosci@huawei.com"

dir="$(pwd)"

if cat /root/.ssh/known_hosts | grep "dgggit09-rd.huawei.com" > /dev/null;then
    echo "Key is OK"
else
    echo "$added_key" >> /root/.ssh/known_hosts
fi

echo "$added_key_id_rsa" > /root/.ssh/id_rsa.pub
chmod 644 /root/.ssh/id_rsa.pub

rm -f ./files_list
ssh -p 29418 peulerosci@dgggit09-rd.huawei.com gerrit query --files --current-patch-set change:$GERRIT_CHANGE_NUMBER | grep file: | awk '{print $2}' > files_list
if ! cat ./files_list | grep COMMIT_MSG &> /dev/null;then
    echo "Get gerrit info failed"
    exit $?
fi
set +e
ls /usr/lib/python2.7/site-packages/setuptools*/
if [ $? -ne 0 ];then
    cd ./binaryscan/tool/;tar -xf setuptools-7.0.tar.gz;cd setuptools-7.0
    python setup.py install
    cd $dir
fi
ls /usr/lib/python2.7/site-packages/xlrd-*/
if [ $? -ne 0 ];then
    cd ./binaryscan/tool/; tar -xf xlrd-1.1.0.tar.gz;cd xlrd-1.1.0/
    python setup.py install
    cd $dir
fi
set -e
rm -rf binaryscan/excelReport/*
rm -rf data.txt
python check_binary_diff.py $scanningPath
sh ./../../private_build/lib/sshscp.sh -p "EulerOS_123" -s "data.txt" -d "10.177.119.224:/home/lichen" -r
sh ./../../private_build/lib/sshcmd.sh -c "cd /home/lichen;cat data.txt >>datebase.txt" -m "10.177.119.224" -u "root" -p "EulerOS_123"
rm -rf data.txt
result=$(cat result |grep "success")
if [ "$result" == "success" ];then
    echo "success"
    exit 0
elif [ "$result" == "fail" ];then
    echo "fail"
    echo "测试阶段，失败不会-1"
    exit 1
fi
